/**
 * Copyright  2016
 *
 * 	All right reserved.
 *
 *	Created on  2016年3月8日 下午3:41:20
 * 
 */
package com.hongxinguoji.manager.company.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hongxinguoji.manager.common.util.EasyUIDataGridResult;
import com.hongxinguoji.manager.common.util.HXResult;
import com.hongxinguoji.manager.common.util.IDUtils;
import com.hongxinguoji.manager.company.pojo.HxCompany;
import com.hongxinguoji.manager.company.service.ICompanySerrvice;

/**
 * @author jing
 *
 */

@Controller
@RequestMapping("/company")
public class CompanyController {

	@Resource
	private ICompanySerrvice companyService;

	/**
	 * 查询
	 * 
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/companylist")
	@ResponseBody
	public EasyUIDataGridResult getCompanyList(Integer page, Integer rows) {
		return companyService.getCompanyList(page, rows);
	}

	/**
	 * 添加
	 * 
	 * @param company
	 * @return
	 */
	@RequestMapping("/addCompany")
	@ResponseBody
	public HXResult addCompany(HxCompany company) {
		try {
			company.setId(IDUtils.getArticleId());
			companyService.addCompany(company);
			return HXResult.ok("添加成功!");
		} catch (Exception e) {
			e.printStackTrace();
			return HXResult.ok("操作失败");
		}
	}

	/**
	 * 删除
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping("deleteCompany")
	@ResponseBody
	public HXResult deleteCompany(String ids) {
		try {
			String[] idStrings = ids.split(",");
			for (String id : idStrings) {
				long long1 = Long.parseLong(id);
				companyService.deleteCompany(long1);
			}
			return HXResult.ok("删除信息成功");
		} catch (Exception e) {
			e.printStackTrace();
			return HXResult.ok("删除信息失败！");
		}

	}

	/**
	 * 更新
	 * 
	 * @param company
	 * @return
	 */
	@RequestMapping("updateCompany")
	@ResponseBody
	public HXResult updateCompany(HxCompany company) {
		try {
			companyService.updateCompany(company);
			return HXResult.ok("更新成功");
		} catch (Exception e) {
			e.printStackTrace();
			return HXResult.ok("更新失败");
		}
	}

	// 企业页面跳转
	@RequestMapping("/{path}")
	public String goPath(@PathVariable String path) {
		return "company/" + path;
	}
}
